from odoo import api, fields, models, _


class House(models.Model):
    _name = 'check.house'
    _description = "This is house information for rent"
    _rec_name = 'name'


    sequence = fields.Integer(
        string='Sequence'
    )


    house_num = fields.Char(
        '房间号'
    )

    name = fields.Char(
        '房间名称'
    )

    house_type = fields.Selection(
        [
            ('0', '单人房'),
            ('1', '双人房'),
            ('2', '总统套房')
        ],
        '房间类型', default="0",
    )

    pre_price = fields.Monetary(
        '预设单价',
        'currency_id'
    )
    currency_id = fields.Many2one(
        'res.currency',
        default=lambda self: self.env.user.company_id.currency_id,
    )  # price helper

    dis_price = fields.Monetary(
        '惠后价',
        'currency_id'

    )

    currency_id = fields.Many2one(
        'res.currency',
        default=lambda self: self.env.user.company_id.currency_id,
    )  # price helper

    dis_rate = fields.Float(
        '折扣率'
    )

    De_time = fields.Date(
        '预离时间',
        required=True
    )

    br_num = fields.Integer(
        '早餐数'
    )
    # 关联

    guest_id = fields.Many2one(
        'check.guest',
    )

   # 状态API True 没人  Flase 有人
    Stage = fields.Boolean(
        "是否可住",
        readonly=True,
        compute='_judge_stage'
    )

    @api.depends('Stage')
    def _judge_stage(self):
        for house in self:
            if house.guest_id:
                house.Stage = False
            else:
                house.Stage = True